'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/follow_tv/pub/test 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, type } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------

		let k = {
			code: 0,
			msg: '请求成功',
			data: 0
		};

		if (type == "int") {
			k.data = vk.pubfn.random(2);
		}

		if (type == "mobile") {
			k.data = '15717117711'
		}

		return k;

		let nows = new Date().getTime()
		// 回传支付事件给百度
		let baiduurl = "https://ocpc.baidu.com/ocpcapi/api/uploadConvertData"
		let baiduhuichuan_result = await uniCloud.httpclient.request(baiduurl, {
			method: 'POST',
			data: {
				"token": "dYkzPvOBCrbTorIlI456aGExFUL0mO2t@nLc2oPkjl4QHR7OkF1mbTYCvKzYvAgHg", //无忧短剧token
				"conversionTypes": [{
					"logidUrl": "bd_vid=P1msP1nvn104n1m3rHRsPWfkn-tLnH-xnNt1nj0sg1PxPHmdnjc1njR3nWbd", //只需要bd_vid=xxxx，百度即可正常接收
					"newType": 93, //付费观剧，参考：https://dev2.baidu.com/content?sceneType=0&pageId=101207&nodeId=655
					"attributeSource": 0, //（转化来源：百度（0），自然流量（1），竞媒（2））
					"interactionsType": 1 //（归因请求方式，点击(1), 播放(2), 关注(3), 分享(4), 点赞(5), 曝光（6）不传使用1，默认为点击归因
				}]
			},
			contentType: 'json', // 指定以application/json发送data内的数据
			dataType: 'json' // 指定返回值为json格式，自动进行parse
		})

		console.log("baiduhuichuan_result=", baiduhuichuan_result);

		// 回传记录入库
		let addhc1 = await db.collection('jl_huichuanjilu').add({
			type: "active_pay",
			platform: "baidu",
			result: baiduhuichuan_result.data,
			time: nows,
		})

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
